package com.flex.mobile.manager;

import org.springframework.flex.messaging.AsyncMessageCreator;
import org.springframework.flex.messaging.MessageTemplate;

import com.flex.mobile.model.OrderMessage;

import flex.messaging.messages.AsyncMessage;
import flex.messaging.util.UUIDUtils;

public class FeedManager {
   private final MessageTemplate template;
   private String clientId;
   
   public FeedManager(MessageTemplate template){
      this.template = template;
      clientId = UUIDUtils.createUUID();
   }
   
   public void sendTaxiOrderMsg(final OrderMessage message, final String subtopic) {
      template.send(new AsyncMessageCreator() {
          public AsyncMessage createMessage() {
              AsyncMessage msg = template.createMessageForDestination("message-feed");
              msg.setHeader("DSSubtopic", subtopic);
              msg.setBody(message);
              msg.setClientId(clientId);
              msg.setMessageId(UUIDUtils.createUUID());
              return msg;
          }
      });
  }
}
